/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DA;

import Control.DBConnector;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author theInterloper
 */
public class common {

    public static int[] getMaxMinID(String string) throws SQLException {
        String getMax ="SELECT MAX("+ string +"ID) AS "+ string + "ID FROM "+ string + ";";
        String getMin ="SELECT MIN("+ string +"ID) AS "+ string + "ID FROM "+ string + ";";
        int min = 0;
        int max = 0;
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
        
        DBConnector dbconnect2 = new DBConnector();
        Connection connect2 = dbconnect2.setUpConnection();
        Statement statement2 = connect2.createStatement();
        
        ResultSet resultsetMax = statement2.executeQuery(getMax);
        ResultSet resultsetMin = statement.executeQuery(getMin);
        
        while(resultsetMax.next()) {
             max = resultsetMax.getInt(1);  
        }
        while(resultsetMin.next()) {
             min = resultsetMin.getInt(1);  
        }
        int[] maxMinArray = {max,min};
        return maxMinArray;
    }

    public static int artistLoginContoller(String userName, String passWord) throws SQLException {
        String returnedPassWord = "";
        int response = 0;
        String findArtistByUserName="select artistPassword from artist where artistUserName = '"+ userName +"'";
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
        ResultSet resultset = statement.executeQuery(findArtistByUserName);
        
        while(resultset.next()) {
             returnedPassWord = resultset.getString(1);  
        }
        System.out.println("The returned password is:" + returnedPassWord + "!!!!");
        
        // User = Artist. Username: True. Password: True
        if(returnedPassWord.equals(passWord)){
            response = 1;
        }
        //User = Artist. Username: True. Password: False
        if(!returnedPassWord.equals(passWord)){
            response = 2;
        }
        //"User != Artist. Username: False. Password: False
        if("".equals(returnedPassWord)){
            response = 3;
        }
        
        return response;
    }

    public static int customerLoginController(String userName, String passWord) throws SQLException {
        String returnedPassWord = "";
        int response = 0;
        String findCustomerByUserName="select customerPassword from customer where customerUserName = '"+ userName +"'";
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
        ResultSet resultset = statement.executeQuery(findCustomerByUserName);
        
        while(resultset.next()) {
             returnedPassWord = resultset.getString(1);  
        }
        System.out.println("The returned password is:" + returnedPassWord);
        
        //"User = Customer. Username: True. Password: True
        if(returnedPassWord.equals(passWord)){
            response = 4;
        }
        //User = Customer. Username: True. Password: False
        if(!returnedPassWord.equals(passWord)){
            response = 5;
        }
        //User != Customer or Artist. Username: False. Password: False"
        if("".equals(returnedPassWord)){
            response = 6;
        }
        
        return response;
    }

}
